<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('入库明细报表')" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.tables.js" type="text/javascript"></script>
<body id="colTb" style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="czsj" name="czsj" placeholder="请选择时间范围" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">产品名称</label>
                        <input type="text" class="layui-input" name="cpmc" id="cpmc" placeholder="请输入产品名称" />

                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">产品编号</label>
                        <input type="text" class="layui-input" name="cpbh" id="cpbh" placeholder="请输入产品编号" />
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal" >重置</button>
                    </div>
                    <input type="hidden" id="cjsj_start" name="cjsj_start">
                    <input type="hidden" id="cjsj_end" name="cjsj_end">
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<script th:inline="javascript">
    var functions = [[${functions}]];
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {
        var myColumns = [];
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    //zzpUtils.refreshTable("#table");
                },
                /*导出*/
                exportEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.cpid;
                        })
                    }
                    /*
                     * 以下是将ids和对象拼接在一起
                     * */
                    var str = zzpUtils.getFormJson($("#searchForm"));
                    var object2 = Object.assign({ids: arr}, str);
                    /*将条件查询和ids传到后台*/
                    zzpUtils.outputXslx({
                        url: "/Instock/InstockExport",
                        data: JSON.stringify(object2)
                    });
                }
            }
        });
        //初始化
        zzpUtils.webSocket.init();
        laydate.render({
            elem: '#czsj',
            type: 'date',
            range: '~',
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    var start=value.toString().substring(0,value.toString().indexOf("~"));
                    var end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#cjsj_start").val(Date.parse(new Date(start)));
                    $("#cjsj_end").val(Date.parse(new Date(end)));
                }else {
                    $("#cjsj_start").val("");
                    $("#cjsj_end").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });
        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {
                alert(row.mc);
            }
        }
        myColumns = getColumns();
        console.log('myColumns', myColumns);
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            autoWidth: false,
            scrollX: true,
            url: '/Instock/list', // 获取数据的地址
            columns: myColumns,
            queryParams: function () {//查询条件

                return  zzpUtils.getFormJson($("#searchForm"));
                console.log('data',data);
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }
        });
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })
        $(".layui-btn-primary").on('click',function () {
            $("#cjsj_start").val("");
            $("#cjsj_end").val("");
            zzpUtils.refreshTable("#table");
        })
        function getColumns() {
            var ajaxdata = [{"field": '',
                "checkbox": true,
            }];
            // 加载动态表格
            $.ajax({
                url: '/zxsswms/Instock/listHeader',
                type: 'POST',
                dataType: "json",
                data: {},
                async: false,
                success: function (returnValue) {
                    console.log('returnValue', returnValue);
                    // 异步获取要动态生成的列
                    // var arr = returnValue.rows;
                    returnValue.column.forEach(function (item) {
                        ajaxdata.push({field: item.prop, title: item.label});
                    })
                    console.log('ajaxdata', ajaxdata);
                }
            });
             return ajaxdata;
        }
    })



</script>
</html>